<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn1">设置cookie</button><br>
    <button class="btn2">获取cookie</button><br>
    <button class="btn3">删除cookie</button><br>
    <script>
        let btn1Ele = document.querySelector(".btn1");
        let btn2Ele = document.querySelector(".btn2");
        let btn3Ele = document.querySelector(".btn3");
        btn1Ele.onclick = function (){
            // document.cookie = "name=ZhangSan;Max-age="+3600 ;//设置的cookie一个小时后过期
            let date = new Date();
            let now = new Date().getTime();
            date.setTime( now + 3600 * 1000 );
            document.cookie = `name=ZhangSan;expires=${date.toUTCString()};`;
        }
        btn2Ele.onclick = function (){
            console.log(document.cookie);
        }
        btn3Ele.onclick = function (){
            document.cookie = "name=1;Max-age=-1";
        }
    </script>
</body>
</html>